package com.xbts.system.domain;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.annotation.Excel;
import com.xbts.common.utils.StringUtils;
import com.xbts.common.core.domain.BaseEntity;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 新闻中心对象 cnNews
 *
 * @author xbts
 * @date 2023-08-15
 */
@Data
@ApiModel("新闻中心对象")
@TableName("cn_news")
public class CnNews extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** 新闻主键 */
    @TableId
    @JsonSerialize(using= ToStringSerializer.class)
    private Long newsId;

    /** 新闻类型*/
    @Excel(name = "新闻类型")
    @ApiModelProperty("新闻类型新闻类型 value = 1,平台公告 value = 2,行业动态 value =,3 政策法规.")
    @NotNull(message = "新闻类型不能为空")
    private Long newsTypeId;

    @ApiModelProperty("新闻类型名称")
    private String newsTypeName;

    @ApiModelProperty("新闻封面地址")
    private String coverUrl;

    /** 新闻标题 */
    @Excel(name = "新闻标题")
    @ApiModelProperty("新闻标题")
    @NotEmpty(message = "新闻标题不能为空")
    private String newsTittle;

    /** 新闻内容 */
    @Excel(name = "新闻内容")
    @ApiModelProperty("新闻内容")
    @NotEmpty(message = "新闻内容不能为空")
    private String newsContent;

    /** 新闻发布日期 */
    @Excel(name = "新闻发布日期")
    @ApiModelProperty("新闻发布日期")
    @NotNull(message = "新闻发布日期不能为空")
    private Date newsDate;

    /** 发布人 */
    @Excel(name = "发布人")
    @ApiModelProperty("发布人")
    private String publisher;

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(newsTypeName),"news_type_name",newsTypeName);
        queryWrapper.eq(Objects.nonNull(newsTypeId),"news_type_id",newsTypeId);
        queryWrapper.eq(Objects.nonNull(newsId),"news_id",newsId);
        queryWrapper.like(StringUtils.isNotEmpty(newsTittle),"news_tittle",newsTittle);
        queryWrapper.eq(Objects.nonNull(newsContent),"news_date",newsContent);
        return queryWrapper;
    }
}